﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentData;

namespace SaturniLibrary.Web.Log.DataProvider
{
    public class SQLServerDataProvider : IWebLogDataProvider
    {
        public string ConnectionStringName { get; set; }

        protected internal IDbContext DefaultContext
        {
            get
            {
                IDbContext context = new DbContext().ConnectionStringName(ConnectionStringName ?? @"default", new SqlServerProvider());
                context.IsolationLevel(IsolationLevel.ReadCommitted);
                return context;
            }
        }
        public void Insert(WebLogDetail webLogDetail) 
        {
            DefaultContext.Insert("web_log_detail")
                              .Column("module_name", webLogDetail.ModuleName)
                              .Column("host_name", webLogDetail.HostName)
                              .Column("exception_source", webLogDetail.ExceptionSource)
                              .Column("exception_type", webLogDetail.ExceptionType)
                              .Column("exception_log_path", webLogDetail.ExceptionLogPath)
                              .Column("client_ip", webLogDetail.ClientIp)
                              .Column("user_agent", webLogDetail.UserAgent)
                              .ExecuteReturnLastId<int>();
        }
    }
}
